package com.fms.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.fms.model.BKCashReceiptJournalModel;

public class BKCashReceiptJournalDAO {
	
	private SqlSessionFactory sqlSessionFactory; 
	
	public BKCashReceiptJournalDAO(){
		sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
	}
	

	/**
	 * Returns the list of all BKCashReceiptJournal instances from the database.
	 * @return the list of all BKCashReceiptJournal instances from the database.
	 */
	@SuppressWarnings("unchecked")
	public List<BKCashReceiptJournalModel> selectAll(){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			List<BKCashReceiptJournalModel> list = session.selectList("BKCashReceiptJournal.getAll");
			return list;
		} finally {
			session.close();
		}
	}

	/**
	 * Returns a BKCashReceiptJournal instance from the database.
	 * @param id primary key value used for lookup.
	 * @return A BKCashReceiptJournal instance with a primary key value equals to pk. null if there is no matching row.
	 */
	public BKCashReceiptJournalModel selectById(int id){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			BKCashReceiptJournalModel bkCashReceiptJournal = (BKCashReceiptJournalModel) session.selectOne("BKCashReceiptJournal.getById",id);
			return bkCashReceiptJournal;
		} finally {
			session.close();
		}
	}

	/**
	 * Updates an instance of BKCashReceiptJournal in the database.
	 * @param BKCashReceiptJournal the instance to be updated.
	 */
	public void update(BKCashReceiptJournalModel bkCashReceiptJournal){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.update("BKCashReceiptJournal.update", bkCashReceiptJournal);
			session.commit();
		} finally {
			session.close();
		}
	}

	/**
	 * Insert an instance of BKCashReceiptJournal into the database.
	 * @param BKCashReceiptJournal the instance to be persisted.
	 */
	public void insert(BKCashReceiptJournalModel bkCashReceiptJournal){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.insert("BKCashReceiptJournal.insert", bkCashReceiptJournal);
			session.commit();
		} finally {
			session.close();
		}
	}

	/**
	 * Delete an instance of BKCashReceiptJournal from the database.
	 * @param id primary key value of the instance to be deleted.
	 */
	public void delete(int id){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.delete("BKCashReceiptJournal.deleteById", id);
			session.commit();
		} finally {
			session.close();
		}
	}
}
